{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## 线性回归代码实现"
   ],
   "execution_count": 1
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "##### 定义一个加载数据的函数"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "source": [
    "def loaddata():\n",
    "    data = np.loadtxt('data/data1.txt',delimiter=',')\n",
    "    n = data.shape[1]-1 #特征数\n",
    "    X = data[:,0:n]\n",
    "    y = data[:,-1].reshape(-1,1)\n",
    "    return X,y"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "execution_count": 5,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "##### 特征归一化\n",
    "归一化有很多种方式，我们这里采取的方式是：对每一个特征，这列中的每个数据分别减去这列的均值，然后再除以这列的方差"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [],
   "source": [
    "def featureNormalize(X):\n",
    "    mu = np.average(X,axis=0)\n",
    "    sigma =np.std(X,axis=0,ddof=1)\n",
    "    X = (X-mu)/sigma\n",
    "    return X,mu,sigma"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "##### LASSO回归核心代码\n",
    "<img src=\"images/08.png\" width=\"300\" align=\"left\"/>\n",
    "<p>\n",
    "<img src=\"images/09.png\" width=\"300\" align=\"left\"/>"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [],
   "source": [
    "def lasso_regression(X, y, iterations,lambd=0.2):\n",
    "    m, n = X.shape\n",
    "    theta = np.matrix(np.zeros((n, 1)))\n",
    "    for it in range(iterations):\n",
    "        for k in range(n):#n个特征\n",
    "            # 计算常量值z_k和p_k\n",
    "            z_k = np.sum(X[:, k]**2)\n",
    "            p_k = 0\n",
    "            for i in range(m):\n",
    "                p_k += X[i, k]*(y[i, 0] - np.sum([X[i, j]*theta[j, 0] for j in range(n) if j != k]))\n",
    "            if p_k < -lambd/2:\n",
    "                w_k = (p_k + lambd/2)/z_k\n",
    "            elif p_k > lambd/2:\n",
    "                w_k = (p_k - lambd/2)/z_k\n",
    "            else:\n",
    "                w_k = 0\n",
    "            theta[k, 0] = w_k\n",
    "    return theta"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[5.83810412]\n",
      " [4.61585958]]\n"
     ]
    },
    {
     "data": {
      "text/plain": "[<matplotlib.lines.Line2D at 0x21a5434ffd0>]"
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": "<Figure size 432x288 with 1 Axes>",
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD5CAYAAAA+0W6bAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAd+klEQVR4nO3de3RU1b0H8O8vMWoEa1BQIRJDRYMPrqApWvEFegtIe0VarfZlq5XWqqtYmmvwibVK7sXa2lVXLVXro2hR0YgiIgpIRVGCAREBHxCUgStBTLUQJY/f/SOZODPnnJkzM+fM2Wfm+1nLJdmZzNk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sADBORMgBPishxqlpw9018DXBVPdvP588DWwAMjPn6MABbA+oLGUpEStAV3rNU9Ymg+2MSVW0RkSXoum9ScAHOKZRgrQBwpIgMEpG9AVwIYG7AfSKDiIgAuBfAOlW9I+j+mEBE+nWPvCEipQDOBrA+0E4FJMgywvNEZAuArwOYJyILgupLUFS1HcCVABag6+bUo6q6NtheBUtEHgHwKoAqEdkiIpcG3aeAjQTwQwCjRWRV9z/nBN2pgPUHsFhE3kTXIGihqj4TcJ8CwZWYREQhxSkUIqKQYoATEYUUA5yIKKQY4EREIcUAJyIKKQY4EVFIMcCJiEKKAU5EFFL/D5T5TKac1Fz2AAAAAElFTkSuQmCC\n"
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "X,y = loaddata()\n",
    "X,mu,sigma = featureNormalize(X)\n",
    "\n",
    "\n",
    "X_1 = np.insert(X, 0, values=1, axis=1)\n",
    "theta = lasso_regression(X_1,y,100)\n",
    "print(theta)\n",
    "plt.scatter(X,y)\n",
    "line = theta[0,0]+theta[1,0]*X\n",
    "plt.plot(X,line)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}